package csci5828.search;

import java.util.Random;
import java.util.concurrent.Callable;

import org.apache.log4j.Logger;

import csci5828.tasks.RequestId;
import csci5828.tasks.impl.TaskSetImpl;

public class SearchTaskSet extends TaskSetImpl<SearchResults> {
	
	private final Logger logger = Logger.getLogger(getClass());

	public SearchTaskSet(final Search[] sources, final String query, 
			             final int mean, final int stdDev) {
		super(new RequestId());
		Random random = new Random();
		for(final Search api : sources){
			final long sleeptime1 = 
				Math.round((stdDev*random.nextGaussian()) + mean);
			addTask(new Callable<SearchResults>(){
				@Override
	    		public SearchResults call() throws Exception {
					logger.info("sleeptime1="+sleeptime1);
					Thread.sleep(sleeptime1);
					return api.search(query);
	    		}
			});
		}
	}

}
